#include "BuffPart.h"

#include "base/core/random.h"
#include "ProtoBuffer/AllProtocol.h"
#include "PlayerMgr.h"
#include "Character/buff/BuffEffectLogicAll.h"
#include "base/core/Profiler.h"


BuffPart::BuffPart()
{
	m_lastTime = 0;
	m_buffDropGoldPercent = 0;
	m_IsExistDeleteTimer = false;
}

BuffPart::~BuffPart()
{

}

bool BuffPart::Init(Creature *pMaster, uint32_t partType, CharacterDBInfo* pCharacterDB)
{
	::Part::Init(pMaster, partType, pCharacterDB);
	g_GetEvent()->Subscribe(dynamic_cast<IEventExecuteSink*>(this), EVENT_UNDER_ATTACK, m_pMaster->GetCid(), 0, "BuffPart::Init");
	g_GetEvent()->Subscribe(dynamic_cast<IEventExecuteSink*>(this), EVENT_ATTACK_SOMEBODY, m_pMaster->GetCid(), 0, "BuffPart::Init");
	g_GetEvent()->Subscribe(dynamic_cast<IEventExecuteSink*>(this), EVENT_CREATURE_CHANGE_SCENE, m_pMaster->GetCid(), 0, "BuffPart::Init");
	g_GetEvent()->Subscribe(dynamic_cast<IEventExecuteSink*>(this), EVENT_PLANE_LEAVE, m_pMaster->GetCid(), CREATURE_PLAYER, "BuffPart::Init");
	g_GetEvent()->Subscribe(dynamic_cast<IEventExecuteSink*>(this), EVENT_PLANE_OPEN, m_pMaster->GetCid(), CREATURE_PLAYER, "BuffPart::Init");
	

	if (pCharacterDB && pCharacterDB->has_buffdata())
	{
		for(int i = 0; i < pCharacterDB->buffdata().buffbaglst_size(); i++)
		{
			const ::ProtoBuf::BuffBagInfo& buffInfo = pCharacterDB->buffdata().buffbaglst(i);

			BuffBagEffectInfo* buffBag = CreateBuffBag();
			buffBag->SetMaster(m_pMaster);
			buffBag->SetBuffPart(this);

			if (buffBag->LoadFromDB(buffInfo) == false)
			{
				DeleteBuffBag(buffBag);
				continue;
			}

			if (BuffEffect_RegisterEffectImp(buffBag, false) == false)
			{
				DeleteBuffBag(buffBag);
				continue;
			}

			BuffEffect_EffectClassifed(buffBag);
		}
	}
	return true;
}

void BuffPart::AllBuffBagFadeOut()
{
	for (auto iter = m_buffBagList.begin(); iter != m_buffBagList.end(); iter++)
	{
		BuffBagEffectInfo* buffBag = iter->second;
		if (buffBag)
		{
			if (buffBag->IsActivated())
			{
				buffBag->BuffEffect_OnEffectFadeOut(false);
			}
		}
	}
}

void BuffPart::ClearBuffBag()
{
	for (auto iter = m_buffBagList.begin(); iter != m_buffBagList.end(); iter++)
	{
		BuffBagEffectInfo* buffBag = iter->second;
		if (buffBag)
		{
			DeleteBuffBag(buffBag);
		}
	}
	m_buffBagList.clear();
	m_ReduceDamageBuffBag.clear();
	m_AddExtraDamageBuffBag.clear();
}

bool BuffPart::UnInit()
{
	KillAllTimerdo();
	g_GetEvent()->UnSubscribeAll(dynamic_cast<IEventExecuteSink*>(this));
	ClearBuffBag();
	return ::Part::UnInit();
}

bool BuffPart::OnMsgHandle(uint32_t cmd, const char* data, uint32_t len)
{
	return true;
}

bool BuffPart::SynOnLogin(PlayerClientInfo& playerInfo)
{
	BuffEffect_SendAllEffectMsg();
	return true;
}

void BuffPart::OnTimer(uint32_t nTimerId)
{
	switch(nTimerId)
	{
	case BUFF_PART_TIME_DEAD_BUFF:
	{
		BuffEffect_CleanupAllFadeOutEffects();
		m_IsExistDeleteTimer = false;
	}
	break;
	}
}

void BuffPart::OnExecute(uint16_t nEventID, uint64_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen)
{
	if (m_pMaster->IsDead())
	{
		return;
	}

	switch (nEventID)
	{
	case EVENT_CREATURE_CHANGE_SCENE:
	case EVENT_PLANE_LEAVE:
	case EVENT_PLANE_OPEN:
	{
		BuffEffect_CleanupAllFadeOutEffects(BuffInfoEndType::BuffInfoSwitchScene);
	}
	break;
	case EVENT_UNDER_ATTACK:
	{
		skillAttackEvent* attackInfo = (skillAttackEvent*)pContext;

		Scene* pCurScene = m_pMaster->GetScene();
		if (pCurScene)
		{
			Creature* pTarget = pCurScene->GetCreature(attackInfo->attacker);
			if (pTarget)
			{
				if (!m_pMaster->IsFriendSide(pTarget))
				{
					BuffEffect_CleanupAllFadeOutEffects(BuffInfoEndType::BuffInfoBeDamagedEnd);
				}
			}
		}
	}
	break;
	case EVENT_ATTACK_SOMEBODY:
	{
		skillAttackEvent* attackInfo = (skillAttackEvent*)pContext;

		for (auto it = m_buffBagList.begin(); it != m_buffBagList.end(); it++)
		{
			BuffBagEffectInfo* buffBag = it->second;
			if (buffBag->IsActivated())
			{
				//
				if (buffBag->GetSenderId() == m_pMaster->GetCid() && buffBag->GetSkillId() == attackInfo->skillId)
				{
					continue;
				}

				if (BuffEffect_IsContainEndType(buffBag, (int32_t)BuffInfoEndType::BuffInfoReleaseSkillEnd))
				{
					buffBag->BuffEffect_OnEffectFadeOut();
				}
			}
		}
	}
		break;
	default:
		break;
	}
}


uint32_t BuffPart::BuffBagList_CountBag(uint32_t stateBagId)
{
	uint32_t count = 0;
	for (auto it = m_buffBagList.begin(); it != m_buffBagList.end(); it++)
	{
		BuffBagEffectInfo* buffBag = it->second;
		if (buffBag->IsActivated() && buffBag->m_stateBagId == stateBagId)
		{
			count++;
		}
	}

	return count;
}

void BuffPart::BuffBagList_EraseBag(uint32_t stateBagId)
{
	for (auto it = m_buffBagList.begin(); it != m_buffBagList.end(); it++)
	{
		BuffBagEffectInfo* buffBag = it->second;
		if (buffBag->IsActivated() && buffBag->m_stateBagId == stateBagId)
		{
			buffBag->BuffEffect_OnEffectFadeOut();
		}
	}
}


bool BuffPart::BuffBagList_FirstBiggerOverrides(uint32_t stateBagId, const std::vector<int32_t>& params)
{
	bool remove = true;
	bool hasBag = false;
	for (auto it = m_buffBagList.begin(); it != m_buffBagList.end(); it++)
	{
		BuffBagEffectInfo* buffBag = it->second;
		if (buffBag->IsActivated() && buffBag->m_stateBagId == stateBagId)
		{
			hasBag = true;
			if (buffBag->m_params.size() > 0 && params.size() > 0)
			{
				if (buffBag->m_params[0] < params[0])
				{
					buffBag->BuffEffect_OnEffectFadeOut();
					remove = false;
				}
			}
		}
	}

	if (!hasBag)
	{
		remove = false;
	}

	return remove;
}

//
void BuffPart::BuffBagList_EraseBagRestTimeLitter(uint32_t stateBagId, uint64_t stateBagTime)
{
	for (auto it = m_buffBagList.begin(); it != m_buffBagList.end(); it++)
	{
		BuffBagEffectInfo* buffBag = it->second;
		if (buffBag->IsActivated() && buffBag->m_stateBagId == stateBagId)
		{
			if (buffBag->CountRestTime() < stateBagTime)
			{
				buffBag->BuffEffect_OnEffectFadeOut();
			}
		}
	}
}

bool BuffPart::BuffEffect_RegisterEffectImp(BuffBagEffectInfo* buffBag, bool syn)
{
	if (m_pMaster->IsDead())
	{
		return false;
	}

	m_buffBagList.emplace(buffBag->GetInstId(), buffBag);

	//LogInfoFmtPrint("start buff bag inst id:%d, state bag id:%d, continuance time:%d", buffBag->GetInstId(), buffBag->GetStateBagId(), buffBag->GetStateBagTime());
	if (syn)
	{
		BuffEffect_SendStartEffectMsg(buffBag);
	}

	if (buffBag->GetStatus() == BuffBagStatus::BUFF_BAG_STATUS_REFIX_START)
	{
		buffBag->BuffEffect_OnEffectActived();
	}

	buffBag->BuffEffect_StartTimer();
	return true;
}

BuffBagEffectInfo* BuffPart::GetBuffBag(uint32_t buffBagInstId)
{
	auto it = m_buffBagList.find(buffBagInstId);
	if (it != m_buffBagList.end())
	{
		return it->second;
	}
	return nullptr;
}

BuffBagEffectInfo* BuffPart::BuffEffect_RegisterEffect(Creature* pSender, uint32_t skillId, uint32_t skillLevel, uint32_t stateBagId, 
	uint32_t stateBagRate, int32_t stateBagTime, const std::vector<int32_t>& params, bool syn /* = false */, uint32_t targetType)
{
	if (pSender == nullptr || m_pMaster->IsDead())
	{
		return nullptr;
	}

	const BuffBagEffectCfgInfo* pBuffCfgInfo = g_GetBuffBagEffectCfgMgr()->FindBuffBag(stateBagId);
	if (pBuffCfgInfo == nullptr)
	{
		return nullptr;
	}

	BuffBagEffectInfo* buffBag = CreateBuffBag();
	buffBag->SetMaster(m_pMaster);

	bool foreverBuffBag = false;
	if (stateBagTime < 0)
	{
		foreverBuffBag = true;
		stateBagTime = 0;
	}

	buffBag->SetBuffPart(this);
	if (buffBag->InitFromData(pSender->GetCid(), skillId, skillLevel, stateBagId, (uint32_t)stateBagTime, params, foreverBuffBag, targetType) == false)
	{
		LogErrFmtPrint("skillId:%d stateBagId:%d initFromData failed", skillId, stateBagId);
		BuffEffect_SendMissMsg(buffBag);
		DeleteBuffBag(buffBag);
		return nullptr;
	}

	bool ret = BuffEffect_CanRegisterEffect(buffBag, params);
	if (ret == false)
	{
		BuffEffect_SendMissMsg(buffBag);
		DeleteBuffBag(buffBag);
		return nullptr;
	}

	
	if (BuffEffect_RegisterEffectImp(buffBag, syn) == false)
	{
		DeleteBuffBag(buffBag);
		return nullptr;
	}

	BuffEffect_EffectClassifed(buffBag);

	if (buffBag->GetStatus() != BuffBagStatus::BUFF_BAG_STATUS_DELAYED_START)
	{
		return buffBag;
	}
	else
	{
		return nullptr;
	}
}

bool BuffPart::BuffEffect_CanRegisterEffect(BuffBagEffectInfo* buffBag, const std::vector<int32_t>& params)
{
	uint32_t stateBagId = buffBag->GetStateBagId();
	uint32_t stateBagTime = buffBag->GetStateBagTime();

	const BuffBagEffectCfgInfo* pBuffCfgInfo = g_GetBuffBagEffectCfgMgr()->FindBuffBag(stateBagId);
	if (pBuffCfgInfo == nullptr)
	{
		return false;
	}

	int bagCount = BuffBagList_CountBag(stateBagId);

	//
	if (bagCount > 0)
	{
		int32_t stateBagRule = pBuffCfgInfo->m_pCfgInfo->stateBagRule;
		if (stateBagRule == BuffStateBagNoSuperPosition)
		{
			//LogInfoFmtPrint("stateBagId:%d BuffStateBagNoSuperPosition",stateBagId);
			return false;
		}
		else if (stateBagRule == BuffStateBagDirectlyOverrides)
		{
			BuffBagList_EraseBag(stateBagId);
		}
		else if (stateBagRule == BuffStateBagLongTimerOverrides)
		{
			BuffBagList_EraseBagRestTimeLitter(stateBagId, stateBagTime);
		}
		else if (stateBagRule == BuffStateBagFirstBiggerOverrides)
		{
			if (BuffBagList_FirstBiggerOverrides(stateBagId, params))
			{
				return false;
			}

		}
		else if (stateBagRule == BuffStateBagEffectSuperPosition)
		{
			if (bagCount >= BuffStateBagEffectSuperPositionMaxCount)
			{
				//LogInfoFmtPrint("stateBagId:%d ", stateBagId);
				return false;
			}
		}
	}

	else
	{

		for (auto it = m_buffBagList.begin(); it != m_buffBagList.end(); it++)
		{
			BuffBagEffectInfo* oldBuffBag = it->second;

			if (oldBuffBag->IsActivated() == false)
			{
				continue;
			}

			if (oldBuffBag->m_stateBagConfigData->HasImmuneEffect())
			{
				if (oldBuffBag->m_stateBagConfigData->IsImmuneEffect(*pBuffCfgInfo))
				{
					//LogInfoFmtPrint("stateBagId:%d immune stateBagId:%d", stateBagId, oldBuffBag->GetStateBagId());
					return false;
				}
			}
		}


		if (pBuffCfgInfo->HasDisperseEffect())
		{
			for (auto it = m_buffBagList.begin(); it != m_buffBagList.end(); it++)
			{
				BuffBagEffectInfo* oldBuffBag = it->second;
				if (oldBuffBag->IsActivated() && pBuffCfgInfo->IsDisperseEffect(*oldBuffBag->m_stateBagConfigData))
				{
					//LogInfoFmtPrint("stateBagId:%d disperse stateBagId:%d", stateBagId, oldBuffBag->GetStateBagId());
					oldBuffBag->BuffEffect_OnEffectFadeOut();
				}
			}
		}
	}
	return true;
}

void BuffPart::BuffEffect_CleanupAllFadeOutEffects(BuffInfoEndType endType)
{
	for (auto it = m_buffBagList.begin(); it != m_buffBagList.end(); it++)
	{
		BuffBagEffectInfo* buffBag = it->second;
		if (buffBag->IsActivated())
		{
			if (BuffEffect_IsContainEndType(buffBag, (int32_t)endType))
			{
				buffBag->BuffEffect_OnEffectFadeOut();
			}
		}
	}	
}

void  BuffPart::BuffEffect_CleanupAllFadeOutEffects(uint32_t skillId)
{
	auto it = m_buffBagList.begin();
	for (; it != m_buffBagList.end();it++)
	{
		BuffBagEffectInfo* buffBag = it->second;
		if (buffBag->IsActivated())
		{
			if (buffBag->GetSkillId() == skillId)
			{
				buffBag->BuffEffect_OnEffectFadeOut();
			}
		}
	}
}

void BuffPart::BuffEffect_CleanupAllFadeOutEffects()
{
	auto it = m_buffBagList.begin();
	for (; it != m_buffBagList.end();)
	{
		BuffBagEffectInfo* buffBag = it->second;

		if (buffBag->IsActivated() == false)
		{
			BuffEffect_ClearEffectClassifed(buffBag);
			buffBag->Clear();
			it->second = nullptr;
			DeleteBuffBag(buffBag);
			it = m_buffBagList.erase(it);
			continue;
		}
		it++;
	}
}

bool BuffPart::BuffEffect_IsContainStartType(BuffBagEffectInfo* buffBag, int32_t endType)
{
	return buffBag->GetStatus() == (BuffBagStatus)endType;
}

bool BuffPart::BuffEffect_IsContainEndType(BuffBagEffectInfo* buffBag, int32_t endType)
{
	return buffBag->IsContainEndType(endType);
}

void BuffPart::BuffEffect_SendAllEffectMsg()
{
	CreatureBuffListRsp Rsp;
	msgBuffList * pData = Rsp.add_list();
	pData->set_cid(m_pMaster->GetCid());
	GetAllBuffInfo(pData);
	m_pMaster->SendDataToClient(EMODULE_ID_SKILL, LOGIC_TO_CLIENT_BUFF_LIST_RSP, (ProtoBufBase*)&Rsp);
}

//
void BuffPart::BuffEffect_SendStartEffectMsg(const BuffBagEffectInfo* buffBag)
{
	if (!m_pMaster)
	{
		return;
	}

	BuffBagDetailInfo detailInfo;
	buffBag->ToMsg(detailInfo);
	m_pMaster->BroadCastData(LOGIC_TO_CLIENT_START_BUFF_BAG, &detailInfo, true);
}

void  BuffPart::BuffEffect_SendEndEffectMsg(const BuffBagEffectInfo* buffBag)
{
	if (!m_pMaster)
	{
		return;
	}


	BuffBagDetailInfo detailInfo;
	detailInfo.set_buff_bag_inst_id(buffBag->GetInstId());
	detailInfo.set_buff_bag_id(buffBag->GetStateBagId());
	detailInfo.set_recver_cid(buffBag->GetMaster()->GetCid());
	detailInfo.set_sender_cid(buffBag->GetSenderId());

	m_pMaster->BroadCastData(LOGIC_TO_CLIENT_END_BUFF_BAG, &detailInfo, true);

}

void BuffPart::BuffEffect_CleanupAllFadeOutEffects(BuffBagEffectInfo* buffBag, bool isSendEndEffect /*= true*/)
{
	std::list<BuffEffectInfo*>& buffList = buffBag->GetBuffList();

	//
	for (std::list<BuffEffectInfo*>::iterator iter = buffList.begin(); iter != buffList.end(); iter++)
	{
		BuffEffectInfo* buff = *iter;
		buff->OnEvent_FadeOut();
	}

	if (isSendEndEffect)
	{
		BuffEffect_SendEndEffectMsg(buffBag);
		//LogInfoFmtPrint("end buff bag inst id:%d, state bag id:%d, continuance time:%d", buffBag->GetInstId(), buffBag->GetStateBagId(), buffBag->GetStateBagTime());
	}

	if (m_IsExistDeleteTimer == false)
	{
		SetTimedo(BUFF_PART_TIME_DEAD_BUFF, 1000, 1);
		m_IsExistDeleteTimer = true;
	}
}

void BuffPart::BuffEffect_ReduceDamage(Creature* pAttack, uint32_t skillId, int32_t &damage)
{
	for (auto it = m_ReduceDamageBuffBag.begin(); it != m_ReduceDamageBuffBag.end();it++)
	{
		BuffBagEffectInfo* buffBag = GetBuffBag(*it);
		if (buffBag && buffBag->IsActivated())
		{
			std::list<BuffEffectInfo*>& buffList = buffBag->GetBuffList();
			std::list<BuffEffectInfo*>::iterator iter = buffList.begin();
			for (; iter != buffList.end(); iter++)
			{
				BuffEffectInfo* buff = *iter;
	
				IBuffLogic* pLogic = buff->GetBuffLogic();
				if (pLogic)
				{
					pLogic->OnEvent_ReduceDamage(buff, m_pMaster, pAttack, skillId, damage);
				}
			}
		}
	}
}

void BuffPart::BuffEffect_AddExtraDamage(Creature* pBeAttacked, uint32_t skillId, int32_t &damage)
{
	for (auto it = m_AddExtraDamageBuffBag.begin(); it != m_AddExtraDamageBuffBag.end();it++)
	{
		BuffBagEffectInfo* buffBag = GetBuffBag(*it);
		if (buffBag && buffBag->IsActivated())
		{
			std::list<BuffEffectInfo*>& buffList = buffBag->GetBuffList();
			std::list<BuffEffectInfo*>::iterator iter = buffList.begin();
			for (; iter != buffList.end(); iter++)
			{
				BuffEffectInfo* buff = *iter;

				IBuffLogic* pLogic = buff->GetBuffLogic();
				if (pLogic)
				{
					pLogic->OnEvent_AddExtraDamage(buff, m_pMaster, pBeAttacked, skillId, damage);
				}
			}
		}
	}
}

void BuffPart::BuffEffect_SendMissMsg(const BuffBagEffectInfo* buffBag)
{
	if (!m_pMaster)
	{
		return;
	}

	BuffBagDetailInfo detailInfo;
	detailInfo.set_buff_bag_inst_id(buffBag->GetInstId());
	detailInfo.set_buff_bag_id(buffBag->GetStateBagId());

	m_pMaster->SendDataToClient(LOGIC_TO_CLIENT_MISS_BUFF_BAG, &detailInfo);
}

bool BuffPart::GetAllBuffInfo(::ProtoBuf::msgBuffList* pBuffData)
{
	//pBuffData->set_cid(m_pMaster->GetCid());
	auto iter = m_buffBagList.begin();
	for(; iter != m_buffBagList.end(); iter++)
	{
		BuffBagEffectInfo* pBuffBag = iter->second;

		if (pBuffBag && pBuffBag->IsActivated())
		{
			//if (pBuffBag->GetStatus() == BuffBagStatus::BUFF_BAG_STATUS_DELAYED_START)
			//{
			//	continue;
			//}

			::ProtoBuf::BuffBagDetailInfo* info = pBuffData->add_info();
			pBuffBag->ToClientMsg(*info);
		}
	}

	return true;
}

void BuffPart::SynLogout()
{
	//AllBuffBagFadeOut();
}

//生物切换逻辑节点
void BuffPart::BeforeChangeLogic()
{
	auto iter = m_buffBagList.begin();
	for(; iter != m_buffBagList.end(); iter++)
	{
		BuffBagEffectInfo* pBuffBag = iter->second;

		if (pBuffBag && pBuffBag->IsActivated() && pBuffBag->GetEffectCfgInfo()->m_pCfgInfo->save == 0)
		{
			pBuffBag->BuffEffect_OnEffectFadeOut();
		}
	}
}

bool BuffPart::SaveDB(CharacterDBInfo& characterDB)
{
	::ProtoBuf::CharacterBuffData* pBuffData = characterDB.mutable_buffdata();

	auto iter = m_buffBagList.begin();
	for(; iter != m_buffBagList.end(); iter++)
	{
		BuffBagEffectInfo* pBuffBag = iter->second;

		if (pBuffBag && pBuffBag->IsActivated() && pBuffBag->GetEffectCfgInfo()->m_pCfgInfo->save != 0)
		{
			::ProtoBuf::BuffBagInfo* info = pBuffData->add_buffbaglst();
			info->set_buffbaginstid(pBuffBag->GetInstId());
			info->set_statebagid(pBuffBag->GetStateBagId());

			info->set_isforever(pBuffBag->IsForever());
			info->set_skillid(pBuffBag->GetSkillId());
			info->set_skilllevel(pBuffBag->GetSkillLevel());

			info->set_sendercid(pBuffBag->GetSenderId());

			info->set_targettype(pBuffBag->GetTargetType());

			info->set_starttime(pBuffBag->GetStartTime());

			uint32_t useTime = (uint32_t)(g_GetGlobalServerTime()->Tick() - pBuffBag->GetStartTime());
			if (pBuffBag->GetStatus() == BuffBagStatus::BUFF_BAG_STATUS_DELAYED_START)
			{
				if (useTime > pBuffBag->GetDelayedTime())
				{
					pBuffBag->SetStatus(BuffBagStatus::BUFF_BAG_STATUS_REFIX_START);
					info->set_statebagtime(pBuffBag->GetStateBagTime());
					info->set_delayedtime(0);
				}
				else
				{
					info->set_statebagtime(pBuffBag->GetStateBagTime());
					info->set_delayedtime(pBuffBag->GetDelayedTime());
				}
			}
			else
			{
				info->set_statebagtime(pBuffBag->GetStateBagTime());
				info->set_delayedtime(0);
			}

			info->set_status((uint32_t)pBuffBag->GetStatus());

			for(int i = 0; i < (int)pBuffBag->m_params.size(); i++)
			{
				info->add_params(pBuffBag->m_params[i]);
			}
		}
	}

	return true;
}

void BuffPart::BuffEffect_ClearEffectClassifed(BuffBagEffectInfo* buffBag)
{
	if (IsReduceDamageBuffBag(buffBag))
	{
		for(auto iter = m_ReduceDamageBuffBag.begin(); iter != m_ReduceDamageBuffBag.end();)
		{
			if (buffBag->GetInstId() == *iter)
			{
				iter = m_ReduceDamageBuffBag.erase(iter);
				continue;
			}
			iter++;
		}
	}

	if (IsAddExtraDamageBuffBag(buffBag))
	{
		for(auto iter = m_AddExtraDamageBuffBag.begin(); iter != m_AddExtraDamageBuffBag.end();)
		{
			if (buffBag->GetInstId() == *iter)
			{
				iter = m_AddExtraDamageBuffBag.erase(iter);
				continue;
			}
			iter++;
		}
	}
}

void BuffPart::BuffEffect_EffectClassifed(BuffBagEffectInfo* buffBag) //锟斤拷BuffBag锟斤拷锟斤拷
{
	if (IsReduceDamageBuffBag(buffBag))
	{
		m_ReduceDamageBuffBag.push_back(buffBag->GetInstId());
	}
	else if (IsAddExtraDamageBuffBag(buffBag))
	{
		m_AddExtraDamageBuffBag.push_back(buffBag->GetInstId());
	}
}

bool BuffPart::IsReduceDamageBuffBag(BuffBagEffectInfo* buffBag) //锟斤拷锟斤拷锟斤拷
{
	if (buffBag)
	{
		for(std::list<BuffEffectInfo*>::iterator iter = buffBag->m_buffList.begin(); iter != buffBag->m_buffList.end(); iter++)
		{
			BuffEffectInfo* pInfo = *iter;
			if (pInfo)
			{
				if (pInfo->GetEffectType() == effectTypeHpShield
						|| pInfo->GetEffectType() == effectTypeWuDi
						|| pInfo->GetEffectType() == effectTypeChangeReduceDamage
						|| pInfo->GetEffectType() == effectTypeBossShield)
				{
					return true;
				}
			}
		}
	}
	return false;
}

bool BuffPart::IsAddExtraDamageBuffBag(BuffBagEffectInfo* buffBag) //
{
	if (buffBag)
	{
		for(std::list<BuffEffectInfo*>::iterator iter = buffBag->m_buffList.begin(); iter != buffBag->m_buffList.end(); iter++)
		{
			BuffEffectInfo* pInfo = *iter;
			if (pInfo)
			{
				if (pInfo->GetEffectType() == effectTypeChangeExtraDamage)
				{
					return true;
				}
			}
		}
	}
	return false;
}

void BuffPart::DelBuffDropGoldPercent(uint64_t count)
{
	if (m_buffDropGoldPercent > count)
		m_buffDropGoldPercent -= count;
	else
		m_buffDropGoldPercent = 0;
}
